unit untLogin;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Buttons, ShellAPI;

type
  TfrmLogin = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    btnCancelar: TBitBtn;
    btnEntrar: TBitBtn;
    Panel1: TPanel;
    edUsuario: TEdit;
    Panel2: TPanel;
    edSenha: TEdit;
    SpeedButton1: TSpeedButton;
    procedure btnCancelarClick(Sender: TObject);
    procedure btnEntrarClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure edSenhaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmLogin: TfrmLogin;

implementation

{$R *.dfm}

uses ClassLogin, FuncoesGenericas;

procedure TfrmLogin.btnCancelarClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TfrmLogin.btnEntrarClick(Sender: TObject);
var
  objLogin : TLogin;
begin
  try
    objLogin := TLogin.Create;

    if objLogin.LogUsuario(edUsuario.Text,edSenha.Text) then
      ModalResult := mrOK
    else
      exit;
  finally
    FreeAndNil(objLogin);
  end;
end;

procedure TfrmLogin.edSenhaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 13 then
    btnEntrar.Click;
end;

procedure TfrmLogin.FormCreate(Sender: TObject);
begin
  if GetRegistro(HKEY_CURRENT_USER, 'SOFTWARE\Mosteiro', 'EM_DESENVOLVIMENTO') = '1' then
  begin
    edUsuario.Text := 'HARLEY';
    edSenha.Text   := '123';
  end else
    edUsuario.Text := GetRegistro(HKEY_CURRENT_USER, 'SOFTWARE\Mosteiro', 'ULTIMOUSUARIOLOGADO');
end;

procedure TfrmLogin.SpeedButton1Click(Sender: TObject);
begin
  ShellExecute(Handle, nil, Pchar(ExtractFilePath(Application.ExeName) + 'Base.udl'), nil, nil, SW_SHOWNORMAL);
end;

end.
